<template>
  <!-- 主容器，设置全屏高度和相对定位 -->
  <div class="main-container">
    <!-- 背景图片容器 -->
    <div class="background-image"></div>

    <!-- 毛玻璃导航栏 -->
    <nav class="glass-navbar">
      <div class="navbar-content">
        <!-- Logo - 绝对定位到左侧 -->
        <div class="navbar-logo">
          <div class="logo">
            <span>沧海彼岸</span>
          </div>
        </div>

        <!-- 中间导航菜单 - 绝对居中 -->
        <div class="navbar-center">
          <ul class="nav-menu">
            <li><a @click="goHome">首页</a></li>
            <li><a href="#wiki">Wiki</a></li>
            <li><a @click="showService">服务</a></li>
            <li><a href="#contact" class="active">联系</a></li>
          </ul>
        </div>

        <!-- 用户头像 - 绝对定位到右侧 -->
        <div class="navbar-right">
          <div class="user-dropdown" @click="toggleDropdown" ref="dropdownRef">
            <!-- 用户头像 -->
            <div class="user-avatar">
              <img
                  :src="userData.avatarUrl"
                  alt="用户头像"
                  class="avatar-image"
              />
              <!-- 在线状态指示器 -->
              <div class="online-indicator"></div>
            </div>

            <!-- 下拉菜单 -->
            <div class="dropdown-menu" :class="{ 'show': isDropdownOpen }">
              <div class="dropdown-header">
                <div class="user-info">
                  <div class="user-name">{{ userData.username }}</div>
                  <div class="user-email">{{ userData.email }}</div>
                </div>
              </div>

              <div class="dropdown-divider"></div>

              <ul class="dropdown-list">
                <li class="dropdown-item" @click="goToProfile">
                  <div class="item-icon">👤</div>
                  <span>个人中心</span>
                </li>
                <li class="dropdown-item" @click="showContact">
                  <div class="item-icon">❓</div>
                  <span>帮助</span>
                </li>
                <li class="dropdown-divider"></li>
                <li class="dropdown-item logout" @click="logout">
                  <div class="item-icon">🚪</div>
                  <span>退出登录</span>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </nav>

    <!-- 主要内容区域 -->
    <div class="main-content" @click="closeDropdown">
      <div class="contact-container">
        <div class="contact-header">
          <h2 class="contact-title">联系我们</h2>
          <p class="contact-subtitle">多种方式与我们取得联系，我们将竭诚为您服务</p>
        </div>

        <!-- 联系方式列表 -->
        <div class="contact-list">
          <!-- 官方QQ群 -->
          <div class="contact-item">
            <div class="contact-icon">
              <div class="icon-wrapper qq-group">
                <span class="icon">👥</span>
              </div>
            </div>
            <div class="contact-info">
              <h3 class="contact-name">官方QQ群</h3>
              <p class="contact-description">加入我们的官方QQ群，与更多用户交流互动</p>
              <div class="contact-value">
                <span class="value-text">701312028</span>
                <button class="copy-btn" @click="copyToClipboard('701312028', 'QQ群号')">
                  <span class="copy-icon">📋</span>
                  <span>复制</span>
                </button>
              </div>
            </div>
          </div>

          <!-- 官方QQ -->
          <div class="contact-item">
            <div class="contact-icon">
              <div class="icon-wrapper qq">
                <span class="icon">💬</span>
              </div>
            </div>
            <div class="contact-info">
              <h3 class="contact-name">官方QQ</h3>
              <p class="contact-description">一对一客服支持，快速解决您的问题</p>
              <div class="contact-value">
                <span class="value-text">2569736791</span>
                <button class="copy-btn" @click="copyToClipboard('2569736791', 'QQ号')">
                  <span class="copy-icon">📋</span>
                  <span>复制</span>
                </button>
              </div>
            </div>
          </div>

          <!-- 官方邮箱 -->
          <div class="contact-item">
            <div class="contact-icon">
              <div class="icon-wrapper email">
                <span class="icon">📧</span>
              </div>
            </div>
            <div class="contact-info">
              <h3 class="contact-name">官方邮箱</h3>
              <p class="contact-description">发送邮件给我们，我们会在24小时内回复</p>
              <div class="contact-value">
                <span class="value-text">2569736791@qq.com</span>
                <button class="copy-btn" @click="copyToClipboard('2569736791@qq.com', '邮箱地址')">
                  <span class="copy-icon">📋</span>
                  <span>复制</span>
                </button>
              </div>
            </div>
          </div>
        </div>

        <!-- 联系提示 -->
        <div class="contact-tips">
          <h3 class="tips-title">联系提示</h3>
          <ul class="tips-list">
            <li class="tip-item">
              <span class="tip-icon">💡</span>
              <span>QQ群内可以与其他用户交流经验，获得更快的帮助</span>
            </li>
            <li class="tip-item">
              <span class="tip-icon">⚡</span>
              <span>紧急问题建议通过官方QQ联系，响应更及时</span>
            </li>
            <li class="tip-item">
              <span class="tip-icon">📝</span>
              <span>邮件联系请详细描述问题，便于我们更好地为您服务</span>
            </li>
          </ul>
        </div>
      </div>

      <!-- 复制成功提示 -->
      <div v-if="showCopyTip" class="copy-tip" :class="{ 'show': showCopyTip }">
        <span class="tip-icon">✅</span>
        <span class="tip-text">{{ copyTipText }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import axios from "axios";

const router = useRouter()
const userData = ref({
  username: '',
  avatarUrl: '',
  email: ''
})
// 下拉菜单状态
const isDropdownOpen = ref(false)
const dropdownRef = ref(null)

// 复制提示
const showCopyTip = ref(false)
const copyTipText = ref('')

onMounted(async () => {
  try {
    const response = await axios.get('/api/user/profile');
    console.log('User profile:', response.data);
    userData.value = response.data.data
    console.log(userData)
    console.log(userData.value.avatarUrl)
  } catch (error) {
    console.error('Error login:', error);
    return false;
  }
})
// 切换下拉菜单
const toggleDropdown = () => {
  isDropdownOpen.value = !isDropdownOpen.value
}

// 关闭下拉菜单
const closeDropdown = () => {
  isDropdownOpen.value = false
}

// 点击外部区域关闭下拉菜单
const handleClickOutside = (event) => {
  if (dropdownRef.value && !dropdownRef.value.contains(event.target)) {
    closeDropdown()
  }
}

// 导航方法
const goHome = async () => {
  console.log('跳转到主页')
  await router.push('/main')
}

const goToProfile = async () => {
  console.log('跳转到个人中心')
  await router.push('/user_profile')
  closeDropdown()
}

const logout = async () => {
  closeDropdown()
  try {
    const response = await axios.post('/api/logout');
    if (response.data.data.code === 1)
      await router.push('/login')
  } catch (error) {
    console.error('Error login:', error);
    return false;
  }
}

// 复制到剪贴板
const copyToClipboard = async (text, type) => {
  try {
    await navigator.clipboard.writeText(text)
    copyTipText.value = `${type}已复制到剪贴板`
    showCopyTip.value = true

    // 3秒后隐藏提示
    setTimeout(() => {
      showCopyTip.value = false
    }, 3000)
  } catch (err) {
    console.error('复制失败:', err)
    // 降级方案：使用传统方法复制
    const textArea = document.createElement('textarea')
    textArea.value = text
    document.body.appendChild(textArea)
    textArea.select()
    try {
      document.execCommand('copy')
      copyTipText.value = `${type}已复制到剪贴板`
      showCopyTip.value = true
      setTimeout(() => {
        showCopyTip.value = false
      }, 3000)
    } catch (err) {
      console.error('传统方法复制也失败了:', err)
    } finally {
      document.body.removeChild(textArea)
    }
  }
}
const showService = async () => {
  console.log('跳转到服务页面')
  await router.push('/service')
}


// 生命周期钩子
onMounted(() => {
  console.log('Contact页面已加载完成')

  // 确保页面没有滚动条
  document.body.style.margin = '0'
  document.body.style.padding = '0'
  document.body.style.overflow = 'hidden'
  document.documentElement.style.margin = '0'
  document.documentElement.style.padding = '0'
  document.documentElement.style.overflow = 'hidden'

  // 添加全局点击事件监听器
  document.addEventListener('click', handleClickOutside)
})

onUnmounted(() => {
  document.removeEventListener('click', handleClickOutside)
})
</script>

<style scoped>
/* 主容器样式 - 设置全屏显示 */
.main-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
}

/* 背景图片样式 */
.background-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background-image: url('@/assets/picture/picture4.jpg?height=1080&width=1920');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  image-rendering: crisp-edges;
  box-sizing: border-box;
}

/* 毛玻璃导航栏样式 */
.glass-navbar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 80px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  animation: slideDown 0.6s ease-out; /* 导航栏下滑动画 */
}

/* 导航栏内容容器 */
.navbar-content {
  position: relative;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  box-sizing: border-box;
}

/* Logo区域 */
.navbar-logo {
  position: absolute;
  left: 2rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1002;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

/* 导航栏中间区域 */
.navbar-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
}

/* 导航菜单样式 */
.nav-menu {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 2rem;
  white-space: nowrap;
}

.nav-menu li {
  margin: 0;
  padding: 0;
}

.nav-menu a {
  color: rgba(255, 255, 255, 0.8); /* 白色文字，半透明 */
  text-decoration: none; /* 移除下划线 */
  font-size: 1rem; /* 字体大小 */
  font-weight: 500; /* 中等粗细 */
  padding: 0.5rem 1rem; /* 内边距 */
  border-radius: 6px; /* 圆角 */
  transition: all 0.3s ease; /* 平滑过渡效果 */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); /* 文字阴影 */
  cursor: pointer; /* 鼠标指针 */
  display: block; /* 块级元素 */
}

.nav-menu a:hover {
  color: rgba(255, 255, 255, 1);
}

.nav-menu a.active {
  color: rgba(255, 255, 255, 1);
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

/* 导航栏右侧区域 */
.navbar-right {
  position: absolute;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1002;
}

/* 用户下拉菜单容器 */
.user-dropdown {
  position: relative;
  display: inline-block;
  z-index: 1003;
}

/* 用户头像样式 */
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.2);
  position: relative;
  transition: all 0.2s ease;
}

.user-avatar:hover {
  border-color: rgba(255, 255, 255, 0.5);
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 在线状态指示器 */
.online-indicator {
  position: absolute; /* 绝对定位 */
  bottom: 2px; /* 距离底部 */
  right: 2px; /* 距离右侧 */
  width: 12px; /* 指示器宽度 */
  height: 12px; /* 指示器高度 */
  background: #4ade80; /* 绿色表示在线 */
  border: 2px solid white; /* 白色边框 */
  border-radius: 50%; /* 圆形 */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); /* 阴影 */
}

/* 下拉菜单样式 */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 200px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 0.5rem 0;
  z-index: 1004;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* 下拉菜单头部 */
.dropdown-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

/* 用户信息 */
.user-info {
  color: rgba(255, 255, 255, 0.8);
}

.user-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.user-email {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 下拉菜单分割线 */
.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0.25rem 0;
}

/* 下拉菜单列表 */
.dropdown-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
}

/* 下拉菜单项 */
.dropdown-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 1);
  transform: translateX(2px);
}

.dropdown-item.logout {
  color: rgba(255, 100, 100, 0.9);
}

.dropdown-item.logout:hover {
  background: rgba(255, 100, 100, 0.15);
  color: rgba(255, 80, 80, 1);
}

.item-icon {
  margin-right: 0.5rem;
  font-size: 0.9rem;
  width: 16px;
  text-align: center;
  opacity: 0.8;
}

/* 主要内容区域 */
.main-content {
  position: absolute;
  top: 80px;
  left: 0;
  width: 100%;
  height: calc(100% - 80px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem;
  box-sizing: border-box;
  overflow: hidden;
}

/* 联系我们容器 */
.contact-container {
  width: 100%;
  max-width: 700px;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.8s ease-out 0.2s both;
}

/* 联系页面头部 */
.contact-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  position: relative;
}

.contact-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 0.5rem 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.contact-subtitle {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 联系方式列表 */
.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;

  /* 自定义滚动条样式 */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* Webkit浏览器滚动条样式 */
.contact-list::-webkit-scrollbar {
  width: 6px;
}

.contact-list::-webkit-scrollbar-track {
  background: transparent;
}

.contact-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.contact-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* 联系方式项 */
.contact-item {
  display: flex;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.contact-item:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* 联系方式图标 */
.contact-icon {
  margin-right: 1.5rem;
  flex-shrink: 0;
}

.icon-wrapper {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.icon-wrapper.qq-group {
  background: rgba(52, 152, 219, 0.2);
}

.icon-wrapper.qq {
  background: rgba(46, 204, 113, 0.2);
}

.icon-wrapper.email {
  background: rgba(231, 76, 60, 0.2);
}

/* 联系方式信息 */
.contact-info {
  flex: 1;
}

.contact-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 0.5rem 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.contact-description {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 1rem 0;
  line-height: 1.5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.contact-value {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.value-text {
  font-size: 1rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
  padding: 0.5rem 1rem;
  border-radius: 8px;
}

/* 复制按钮 */
.copy-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 1);
}

/* 联系提示 */
.contact-tips {
  padding: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

.tips-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 1rem 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tips-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tip-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tip-icon {
  margin-right: 0.5rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* 复制提示 */
.copy-tip {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  transition: all 0.3s ease;
  opacity: 0;
}

.copy-tip.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 动画效果 */
@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 - 平板设备 */
@media (max-width: 768px) {
  .navbar-center {
    display: none;
  }

  .main-content {
    top: 60px;
    height: calc(100% - 60px);
    padding: 1rem;
  }

  .glass-navbar {
    height: 60px;
  }

  .contact-container {
    max-width: 100%;
  }

  .contact-header {
    padding: 1rem;
  }

  .contact-title {
    font-size: 1.3rem;
  }

  .contact-item {
    flex-direction: column;
    text-align: center;
    padding: 1rem;
  }

  .contact-icon {
    margin-right: 0;
    margin-bottom: 1rem;
    align-self: center;
  }

  .contact-value {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* 超小屏幕适配 */
@media (max-width: 480px) {
  .main-content {
    padding: 0.5rem;
  }

  .contact-header {
    padding: 0.75rem;
  }

  .contact-title {
    font-size: 1.2rem;
  }

  .contact-item {
    padding: 0.75rem;
  }

  .icon-wrapper {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
  }
}
</style>